<?php

namespace Proj\ResManBundle\Controller;

//use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Proj\ResManBundle\Entity\Project;
use Proj\ResmanBundle\Form\ProjectType;

/**
 * @Route("/demo")
 */
class DemoController extends Controller
{
    /**
     * @Route("/date", name="demo_date")
     */
    public function dateAction()
    {   
        $project = new Project();
        $form = $this->createForm(new ProjectType(), $project);
        $request = $this->getRequest();
        
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);
            if ($form->isValid()) {
                $project->setState("pending");
                $project->setCreationDate(new \DateTime());
                $em = $this->getDoctrine()->getManager();
                $em->persist($project);
                $em->flush();
                
//                $this->get('session')->setFlash('proj-notice', 'Finance has been successfully added.');
                
                return $this->redirect($this->generateUrl('demo_date'));
            }
        }
        
        return $this->render(
            'ProjResManBundle:Demo:date.html.twig',
            array('form' => $form->createView())
        );
    }
}